package com.sugon.thread;

import java.util.concurrent.CyclicBarrier;

public class TestCyclicBarrier {

	public static void main(String[] args) {
		CyclicBarrier cb = new CyclicBarrier(3);
		
		class Travel extends Thread{
			String name;
			String city;
			int time;
			public Travel(String name, String city, int time) {
				super();
				this.name = name;
				this.city = city;
				this.time = time;
			}
			public void run(){
				System.out.println(name+" 从 "+city+" 出发");
				try {
					Thread.sleep(time);
					System.out.println(name+" 到达北京");
					cb.await();
				} catch (Exception e) {
					e.printStackTrace();
				}

				System.out.println(name+" 去爬长城");
			}
		}
		
		Thread t1 = new Travel("Huxz","天津",2000);
		Thread t2 = new Travel("Liucy","上海",5000);
		Thread t3 = new Travel("Liangb","南京",10000);
		t1.start();
		t2.start();
		t3.start();
	}

}

